//
//  QuickFingerScrollViewLayer.cpp
//  CanYouDoIt
//
//  Created by hoangtx on 7/8/13.
//
//

#include "QuickFingerScrollViewLayer.h"
#include "StaticVariables.h"
#include "SceneManager.h"

bool QuickFingerScrollViewLayer::init(){
    ScrollViewLayer::init();
    navigationBar = NavigationBar::create();
    this->addChild(navigationBar);
    navigationBar->setTitle("quick finger");
    descriptionContentArray = CCArray::create();
    descriptionContentArray->retain();
    
    descriptionContentArray->addObject(CCString::create("tap as fast as you can in 10 seconds"));
    descriptionContentArray->addObject(CCString::create("the button will appear randomly. can you touch it 100 times in 15 seconds"));
    descriptionContentArray->addObject(CCString::create("the button will move in circle. Tap it"));
    descriptionContentArray->addObject(CCString::create("Avoid the flying circle around."));
    descriptionContentArray->addObject(CCString::create("Follow the rolling circles"));
    descriptionContentArray->addObject(CCString::create("Choose the right color"));
    descriptionContentArray->addObject(CCString::create("Tap buttons in the right ORDER"));
    descriptionContentArray->addObject(CCString::create("Square, Triangle, Cross and Circle"));
    descriptionContentArray->addObject(CCString::create("Throw your balls"));
    return true;
}

QuickFingerScrollViewLayer* QuickFingerScrollViewLayer::create(int numOfPages){
    QuickFingerScrollViewLayer* scrollView = QuickFingerScrollViewLayer::create();
    scrollView->setUpPages(numOfPages);
    scrollView->setUpColor();
    scrollView->descriptionLayer = DescriptionLayer::create();
    scrollView->descriptionLayer->setPosY(scrollView->getScrollingArea().origin.y/2);
    scrollView->updateDescription();
    scrollView->addChild(scrollView->descriptionLayer);
    
    return scrollView;
}
void QuickFingerScrollViewLayer::setUpColor(){
    getPageAt(0)->sprite->setColor(ccc3(60,200,30));
    getPageAt(1)->sprite->setColor(ccc3(200,32,40));
    getPageAt(2)->sprite->setColor(ccc3(100,202,200));
    getPageAt(3)->sprite->setColor(ccc3(200,200,48));
    getPageAt(4)->sprite->setColor(ccc3(200,40,100));
    getPageAt(5)->sprite->setColor(ccc3(50,50,180));
    getPageAt(6)->sprite->setColor(ccc3(210,148,50));
    getPageAt(7)->sprite->setColor(ccc3(137,46,201));
    getPageAt(8)->sprite->setColor(ccc3(80,146,100));
}

void QuickFingerScrollViewLayer::onTapAtPage(cocos2d::CCObject *sender){
    int tapIndex = ((CCInteger*)sender)->getValue();
    CCLOG("tap at %i",tapIndex);
    switch (tapIndex) {
        case 0:{
            CCTransitionFade* transition = CCTransitionFade::create(TRANSITION_DURATION, SceneManager::sharedInstance()->staticTapScene, ccc3(0, 0, 0));
            CCDirector::sharedDirector()->replaceScene(transition);
        }
            break;
            
        case 1:{
            CCTransitionFade* transition = CCTransitionFade::create(TRANSITION_DURATION, SceneManager::sharedInstance()->hideAndSeekScene, ccc3(0, 0, 0));
            CCDirector::sharedDirector()->replaceScene(transition);
        }
            break;
            
        case 2:{
            CCTransitionFade* transition = CCTransitionFade::create(TRANSITION_DURATION, SceneManager::sharedInstance()->quickCircleTapScene, ccc3(0, 0, 0));
            CCDirector::sharedDirector()->replaceScene(transition);
        }
            break;
            
        case 3:{
            CCTransitionFade* transition = CCTransitionFade::create(TRANSITION_DURATION, SceneManager::sharedInstance()->avoidTheCircleGameScene, ccc3(0, 0, 0));
            CCDirector::sharedDirector()->replaceScene(transition);
        }
            break;
            
        case 4:{
            CCTransitionFade* transition = CCTransitionFade::create(TRANSITION_DURATION, SceneManager::sharedInstance()->followTheCircleGameScene, ccc3(0, 0, 0));
            CCDirector::sharedDirector()->replaceScene(transition);
        }
            break;
            
        case 5:{
            CCTransitionFade* transition = CCTransitionFade::create(TRANSITION_DURATION, SceneManager::sharedInstance()->chooseTheRightColorGameScene, ccc3(0, 0, 0));
            CCDirector::sharedDirector()->replaceScene(transition);
        }
            break;
        case 6:{
            CCTransitionFade* transition = CCTransitionFade::create(TRANSITION_DURATION, SceneManager::sharedInstance()->orderTapGameScene, ccc3(0, 0, 0));
            CCDirector::sharedDirector()->replaceScene(transition);
        }
            break;
            
        case 7:{
            CCTransitionFade* transition = CCTransitionFade::create(TRANSITION_DURATION, SceneManager::sharedInstance()->controllerSplashGameScene, ccc3(0, 0, 0));
            CCDirector::sharedDirector()->replaceScene(transition);
        }
            break;
            
        case 8:{
            CCTransitionFade* transition = CCTransitionFade::create(TRANSITION_DURATION, SceneManager::sharedInstance()->throwingBallGameScene, ccc3(0, 0, 0));
            CCDirector::sharedDirector()->replaceScene(transition);
        }
            break;
    }
    
}

void QuickFingerScrollViewLayer::updateDescription(){
    CCString* stringObject = (CCString*)descriptionContentArray->objectAtIndex(currentPage);
    descriptionLayer->setDescriptionString(stringObject->getCString());
}

void QuickFingerScrollViewLayer::didBeginMovingPages(){
    this->updateDescription();
}

